package com.teprinciple.wanandroid.ui.page

import androidx.compose.foundation.*
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.teprinciple.wanandroid.R
import com.teprinciple.wanandroid.ui.theme.black1
import com.teprinciple.wanandroid.ui.theme.blue1

@Composable
fun MinePage() {

    Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState())) {
        Column(
            modifier = Modifier.height(180.dp)
                .fillMaxWidth()
                .background(blue1),
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.Center
        ) {
            Image(
                painter = painterResource(id = R.mipmap.ic_head),
                contentDescription = null,
                modifier = Modifier
                    .size(70.dp)
                    .clip(CircleShape)
                    .pointerInput(Unit) {
                        detectTapGestures(
                            onPress = {

                            }
                        )
                    }
            )

            Text(
                text = "Teprinciple",
                modifier = Modifier.padding(top = 15.dp),
                color = Color.White,
                fontSize = 18.sp,
                fontWeight = FontWeight.Bold
            )
        }

        val item = arrayListOf(
            Pair("我的积分", R.mipmap.ic_jifeng),
            Pair("我的收藏", R.mipmap.ic_collect_fill),
            Pair("待办事项", R.mipmap.ic_todo),
            Pair("系统设置", R.mipmap.ic_setting)
        )

        item.forEach {
            MineItem(it)
        }
    }
}

@Composable
private fun MineItem(item: Pair<String, Int>) {
    Row(
        verticalAlignment = Alignment.CenterVertically,
        modifier = Modifier
            .height(50.dp)
            .fillMaxWidth()
            .padding(12.dp, 0.dp)
    ) {

        Image(
            painter = painterResource(id = item.second),
            contentDescription = item.first,
            modifier = Modifier.size(28.dp).padding(end = 8.dp),
        )

        Text(
            text = item.first,
            fontSize = 15.sp,
            color = black1,
            modifier = Modifier.weight(1f)
        )

        Image(
            painter = painterResource(id = R.mipmap.ic_arraw),
            contentDescription = "",
            modifier = Modifier.width(10.dp)
        )
    }
}

@Composable
@Preview(backgroundColor = 0xffffff)
fun MinePreview() {
    MinePage()
}